
const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    Car: cc.Node = null

    @property(cc.Graphics)
    linePhysics: cc.Graphics = null

    run: boolean
    originPos: cc.Vec2 
    // LIFE-CYCLE CALLBACKS:

    start() {
        this.originPos = this.node.position
    }

    follow() {
        this.run = true
    }

    restart() {
        this.run = false
        this.node.setPosition(this.originPos)
        for (let i of this.Car.children) {
            i.destroy()
        }
        this.linePhysics.clear()
    }

    update(dt) {
        if (this.run) {
            this.node.position = cc.v2(this.Car.children[0].position.x + 200, 0)
        }

    }
}
